package com.season.seasonStudy.smallTool;

import lombok.AllArgsConstructor;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

public class TEst {
    public static void main(String[] args) throws Exception {
        // 1.读取
        String standingbookPath = "F:\\standingbook.sql";
        String standingbookData = read(standingbookPath);
        // 2. 偷换
        for (DataEntity change : list()) {
            standingbookData = standingbookData.replace(change.getKey(), change.getValue());
            Thread.sleep(500);
        }
        // 3.写入
        write(standingbookPath, standingbookData);

        // 1.读取
        String taurusPath = "F:\\taurus.sql";
        String taurusData = read(taurusPath);
        // 2. 偷换
        for (DataEntity change : list()) {
            taurusData = taurusData.replace(change.getKey(), change.getValue());
            Thread.sleep(500);
        }
        // 3.写入
        write(taurusPath, taurusData);
    }

    /**
     * 写入数据
     *
     * @param path
     * @param content
     */
    public static void write(String path, String content) {
        try {
            File file = new File(path);
            // if file doesnt exists, then create it
            if (!file.exists()) {
                file.createNewFile();
            }

            FileWriter fw = new FileWriter(file.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(content);
            bw.close();
            System.out.println("Done");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static String read(String path) throws Exception {
        File file = new File(path);
        if (!file.exists()) {
            return null;
        }
        FileInputStream inputStream = new FileInputStream(file);
        int length = inputStream.available();
        byte[] bytes = new byte[length];
        inputStream.read(bytes);
        inputStream.close();
        String str = new String(bytes, StandardCharsets.UTF_8);
        return str;
    }

    /**
     * 要替换的文本
     *
     * @return
     */
    public static List<DataEntity> list() {
        ArrayList<DataEntity> list = new ArrayList<>();
        list.add(new DataEntity("336801966170726401", "19613"));
        list.add(new DataEntity("387245259819737089", "19613"));
        list.add(new DataEntity("336801966195892225", "19614"));
        list.add(new DataEntity("387245259794571265", "19614"));
        list.add(new DataEntity("336801966242029569", "19891"));
        list.add(new DataEntity("387245400094040064", "19891"));
        list.add(new DataEntity("336801966288166913", "19899"));
        list.add(new DataEntity("387245400035319808", "19899"));
        list.add(new DataEntity("336801966921506816", "19924"));
        list.add(new DataEntity("387245400005959680", "19924"));
        list.add(new DataEntity("336801966942478337", "19925"));
        list.add(new DataEntity("387245399976599552", "19925"));
        list.add(new DataEntity("336801966997004288", "19927"));
        list.add(new DataEntity("387245399922073600", "19927"));
        list.add(new DataEntity("336801967043141632", "19940"));
        list.add(new DataEntity("387245400173731840", "19940"));
        list.add(new DataEntity("336801967701647360", "19970"));
        list.add(new DataEntity("387245399120961536", "19970"));
        list.add(new DataEntity("336801969022853120", "20004"));
        list.add(new DataEntity("387245259194785792", "20004"));
        list.add(new DataEntity("336801969052213248", "20005"));
        list.add(new DataEntity("387245259165425665", "20005"));
        list.add(new DataEntity("336801969077379073", "20007"));
        list.add(new DataEntity("387245259144454144", "20007"));
        list.add(new DataEntity("336801970419556352", "20018"));
        list.add(new DataEntity("387245259379335168", "20018"));
        list.add(new DataEntity("336801970448916480", "20020"));
        list.add(new DataEntity("387245259354169344", "20020"));
        list.add(new DataEntity("336801970474082305", "20024"));
        list.add(new DataEntity("387245259329003520", "20024"));
        list.add(new DataEntity("336801972105666561", "20091"));
        list.add(new DataEntity("387246238984200192", "20091"));
        list.add(new DataEntity("336801972155998209", "20109"));
        list.add(new DataEntity("387246238778679296", "20109"));
        list.add(new DataEntity("336801972185358337", "20110"));
        list.add(new DataEntity("387246238745124864", "20110"));
        list.add(new DataEntity("336801972332158977", "20132"));
        list.add(new DataEntity("387245399179681792", "20132"));
        list.add(new DataEntity("336801972906778624", "20136"));
        list.add(new DataEntity("387246238849982464", "20136"));
        list.add(new DataEntity("336801972961304576", "20138"));
        list.add(new DataEntity("387246238711570432", "20138"));
        list.add(new DataEntity("336801972986470401", "20139"));
        list.add(new DataEntity("387246238682210304", "20139"));
        list.add(new DataEntity("336801973040996353", "20141"));
        list.add(new DataEntity("387246238648655872", "20141"));
        list.add(new DataEntity("336801973070356480", "20142"));
        list.add(new DataEntity("387326342074621952", "20142"));
        list.add(new DataEntity("336801973162631168", "20145"));
        list.add(new DataEntity("387326342103982080", "20145"));
        list.add(new DataEntity("336801974504808449", "20154"));
        list.add(new DataEntity("387245399263567872", "20154"));
        list.add(new DataEntity("336801980246810624", "20244"));
        list.add(new DataEntity("387246239630123008", "20244"));
        list.add(new DataEntity("336801980330696704", "20247"));
        list.add(new DataEntity("387246239533654016", "20247"));
        list.add(new DataEntity("336801980385222657", "20249"));
        list.add(new DataEntity("387246239495905281", "20249"));
        list.add(new DataEntity("336801980414582785", "20250"));
        list.add(new DataEntity("387246239462350848", "20250"));
        list.add(new DataEntity("336801981060505601", "20256"));
        list.add(new DataEntity("387246239395241984", "20256"));
        list.add(new DataEntity("336801981085671425", "20257"));
        list.add(new DataEntity("387246239361687552", "20257"));
        list.add(new DataEntity("336801981140197376", "20259"));
        list.add(new DataEntity("387246239328133120", "20259"));
        list.add(new DataEntity("336801981169557504", "20260"));
        list.add(new DataEntity("387246239298772992", "20260"));
        list.add(new DataEntity("336801983182823425", "20278"));
        list.add(new DataEntity("387246239181332480", "20278"));
        list.add(new DataEntity("336801983560310785", "20284"));
        list.add(new DataEntity("387246239110029313", "20284"));
        list.add(new DataEntity("336801984562749441", "20289"));
        list.add(new DataEntity("387246239055503360", "20289"));
        list.add(new DataEntity("336801984621469696", "20292"));
        list.add(new DataEntity("387246239772729344", "20292"));
        list.add(new DataEntity("336801985430970369", "20304"));
        list.add(new DataEntity("387246239021948928", "20304"));
        list.add(new DataEntity("336801987603619841", "20321"));
        list.add(new DataEntity("387246239210692608", "20321"));
        list.add(new DataEntity("336801994536804352", "20380"));
        list.add(new DataEntity("387245399032881153", "20380"));
        list.add(new DataEntity("336801997669949441", "20562"));
        list.add(new DataEntity("387245397959139328", "20562"));
        list.add(new DataEntity("336801997699309569", "20563"));
        list.add(new DataEntity("387245397929779200", "20563"));
        list.add(new DataEntity("336801997728669697", "20564"));
        list.add(new DataEntity("387245397900419073", "20564"));
        list.add(new DataEntity("336801997758029824", "20565"));
        list.add(new DataEntity("387245397875253248", "20565"));
        list.add(new DataEntity("336801997787389953", "20566"));
        list.add(new DataEntity("387245397850087424", "20566"));
        list.add(new DataEntity("336802001545486336", "20928"));
        list.add(new DataEntity("387245396784734208", "20928"));
        list.add(new DataEntity("336802001574846464", "20929"));
        list.add(new DataEntity("387245396755374080", "20929"));
        list.add(new DataEntity("336802001600012289", "20930"));
        list.add(new DataEntity("387245396730208256", "20930"));
        list.add(new DataEntity("336801966351081472", "20932"));
        list.add(new DataEntity("387245396675682305", "20932"));
        list.add(new DataEntity("336802005844647937", "21231"));
        list.add(new DataEntity("387326342137536512", "21231"));
        list.add(new DataEntity("336802011003641856", "21360"));
        list.add(new DataEntity("387245394901491713", "21360"));
        list.add(new DataEntity("336802011087527937", "21363"));
        list.add(new DataEntity("387245394926657537", "21363"));
        return list;
    }


}

@lombok.Data
@AllArgsConstructor
class DataEntity {
    private String key;
    private String value;
}